import ajax from './ajax.js';
import jsonp from 'jsonp';
import { message } from 'antd';

export const reqLogin = (username, password) => ajax("/login", {username, password}, "POST");

export const reqAddUser = (user) => ajax("/manage/user/add", user, "POST");

export const reqWeather = (dis_id) => {
    return new Promise((resolve,reject) => {
        const url = `http://api.map.baidu.com/weather/v1/?district_id=${dis_id}&data_type=all&ak=88tvPrAVahmqxGte8AsT81MPQvRRdv0y`;
        jsonp(url, {}, (err, data) => {
            console.log("jsonp()", err, data);
            if(!err && data.status === "success") {
                const {dayPictrueUrl, weather} = data.results[0].weather_data[0];
                resolve({dayPictrueUrl,weather})
            }
            else {
                message.error("获取天气信息失败!");
            }
        })
    })
}
reqWeather(510703);